﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Spotless.Data
{
    [MetadataType(typeof(Query_Metadata))]
    public partial class Query
    {
        public enum QueryTypes : byte
        {
            Enquiry = 2,
            Complaint = 3
        }

        public enum QuerySource : byte
        {
            Website = 1,
            Email = 2,
            Telephone = 3,
            Letter = 4,
            Retailer = 5
        }

        public enum Retailers : byte
        {
            Other = 1,
            Asda = 2,
            BandQ = 3,
            Boots = 4,
            Boyes = 5,
            C_and_H_Fabrics = 6,
            Cash_and_Carry_Wholesale = 7,
            CDS_Superstores = 8,
            Clarks = 9,
            Coop_Somerfield = 10,
            DCS = 11,
            Decco = 12,
            Discounters = 13,
            Drug_Store_Convenience = 14,
            Dunelm = 15,
            DW_Sports = 16,
            Faith = 17,
            Hobbycraft = 18,
            Home_Hardware = 19,
            Independents = 20,
            JLP = 21,
            Leather_and_Grindery = 22,
            M_and_S_Toiletries = 23,
            Marshal_Coppin = 24,
            Morrisons = 25,
            Next = 26,
            Pets_at_Home = 27,
            Poundstores = 28,
            Rayburn = 29,
            Sainsbury = 30,
            Schuh = 31,
            Semichem = 32,
            Solus = 33,
            STAX = 34,
            Tesco = 35,
            Timpson = 36,
            Unichem = 37,
            Waitrose = 38,
            Wilkinson = 39,   }

        public enum WmManufacturers : byte
        {
            Other = 1,
            AEG= 2,
            Baumatic= 3,
            Beko= 4,
            Belling= 5,
            Bosch= 6,
            Candy= 7,
            Creda= 8,
            Dyson= 9,
            Hoover= 10,
            Hotpoint= 11,
            Indesit= 12,
            LG= 13,
            Matsui= 14,
            Miele= 15,
            Samsung= 16,
            Siemens= 17,
            Whirlpool= 18,
            Zanussi= 19,
            Electrolux= 20,
            SMEG= 21,
            Hitachi= 22,
            Ariston = 23
        }
        
        public enum QueryStatus : byte
        {
            Not_Started = 1,
            In_Progress = 2,
            Complete = 3
        }

        public enum Methods : byte
        {
            Letter = 1,
            Telephone = 2,
            Email = 3
        }

        public enum PaymentTypes : byte
        {
            None = 1,
            Refund = 2,
            Compensation = 3
        }

        public enum CompensationStatusTypes : byte
        {
            Pending = 1,
            Confirm = 2,
            Reject = 3
        }

        public QueryTypes? QueryType
        {
            get
            {
                if (this.QueryTypeId.HasValue)
                    return (QueryTypes)this.QueryTypeId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue)
                    this.QueryTypeId = (byte)value;
                else
                    this.QueryTypeId = null;

            }
        }

        public WmManufacturers? WmManufacturere
        {
            get
            {
                if (this.WmManufacturereId.HasValue)
                    return (WmManufacturers)this.WmManufacturereId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue)
                    this.WmManufacturereId = (byte)value;
                else
                    this.WmManufacturereId= null;

            }
        }

        public QuerySource Source
        {
            get
            {
                return (QuerySource)this.SourceId;
            }
            set
            {
                this.SourceId = (byte)value;
            }
        }

        public QueryStatus Status
        {
            get
            {
                return (QueryStatus)this.StatusId;
            }
            set
            {
                this.StatusId = (byte)value;
            }
        }

        public Methods? Method
        {
            get
            {
                if (this.MethodId.HasValue)
                    return (Methods)this.MethodId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue)
                    this.MethodId = (byte)value;
                else
                    this.MethodId = null;
            }
        }

        public Retailers? Retailer
        {
            get
            {
                if (this.RetailerId.HasValue)
                    return (Retailers)this.RetailerId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue)
                    this.RetailerId = (byte)value;
                else
                    this.RetailerId = null;
            }
        }
 
        public PaymentTypes? PaymentType
        {
            get
            {
                if (this.PaymentTypeId.HasValue)
                    return (PaymentTypes)this.PaymentTypeId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue && value== PaymentTypes.Compensation && !this.CompensationStatus.HasValue)
                    //this.CompensationStatus3 =(CompensationStatusTypes)3;
                    this.CompensationStatus = CompensationStatusTypes.Pending;
                
                if (value.HasValue)
                    this.PaymentTypeId = (byte)value;
                else
                    this.PaymentTypeId= null;
            }
        }

        public CompensationStatusTypes? CompensationStatus
        {
            get
            {
                if (this.CompensationStatusId.HasValue)
                    return (CompensationStatusTypes)this.CompensationStatusId;
                else
                    return null;
            }
            set
            {
                if (value.HasValue)
                    this.CompensationStatusId = (byte)value;
                else
                    this.CompensationStatusId= null;
            }
        }

        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (action == System.Data.Linq.ChangeAction.Insert)
                this._Created = this._Updated = DateTime.Now;
            else if(action == System.Data.Linq.ChangeAction.Update)
                this._Updated = DateTime.Now;
        }
    }

    public class Query_Metadata
    {
        [DisplayName("Id")]
        public int QueryId{ get; set; }

        [DisplayName("Enquiry Date")]
        public System.DateTime EnquiryDate { get; set; }

        [DisplayName("Source")]
        //[Range(typeof(byte), "1", "5", ErrorMessage = "{0} is required.")] 
        public byte SourceId { get; set; }
 
        [DisplayName("First Name")]
        public string FirstName { get; set; }

        [DisplayName("Last Name")]
        public string LastName { get; set; }

        [DisplayName("Email")]
        public string Email { get; set; }

        [DisplayName("Address")]
        public string AddressLine1 { get; set; }

        [DisplayName("Address 2")]
        public string AddressLine2 { get; set; }

        [DisplayName("Town")]
        public string Town { get; set; }

        [DisplayName("County")]
        public string County { get; set; }

        [DisplayName("Post Code")]
        public string PostCode { get; set; }

        [DisplayName("Country")]
        public string Country { get; set; }

        //[Required(ErrorMessage="{0} is required")]
        [DisplayName("Category")]
        public int CategoryId { get; set; }
        
        [DisplayName("Store")]
        public System.Nullable<byte> StoreId { get; set; }

        //[Required]
        [Range(typeof(byte), "1", "3", ErrorMessage = "{0} is Required.")] 
        [DisplayName("Priority")]
        public byte Priority { get; set; }

        //[Required]
        //[Range(1,3, ErrorMessage = "{0} is required.")] 
        [DisplayName("Status")]
        public byte StatusId { get; set; }
        
        //[Range(1, 3, ErrorMessage = "{0} is required.")] 
        [DisplayName("Method")]
        public byte? Method { get; set; }

        [DisplayName("Payment Type")]
        public byte? PaymentType { get; set; }

        [DisplayName("Retailer Name")]
        public byte? Retailer { get; set; }

        [DisplayName("Machine Manufacturer")]
        public byte? WmManufacturere { get; set; }

        [DisplayName("Machine Model")]
        public string WmModel { get; set; }

        [DisplayName("Batch Code")]
        public string BatchCode { get; set; }
        //is this needed if its automatically being set if compensations been selected??
        // [DisplayName("Compensation Status")]
        // public byte? CompensationStatus { get; set; }
        
        [DisplayName("Amount")]
        public float? Amount { get; set; }

        [DisplayName("Free Text Area")]
        public float FreeTextArea { get; set; }

        [DisplayName("Product")]
        //[Range(1, 1000000, ErrorMessage= "{0} is required")]
        //[Required(ErrorMessage="{0} is required")]
        public int ProductId { get; set; }

        [DisplayName("Query Selection")]
        //[Range(1, 1000000, ErrorMessage = "{0} is required")]
        //[Required(ErrorMessage = "{0} is rrequired")]
        public int QuerySelectionId { get; set; }
                
        public byte Telephone { get; set; }
    
    }
}
